/*
 *
 * Copyright (c) 2013-2021, Alibaba Group Holding Limited;
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package com.aliyun.polardbx.binlog.daemon.collector;

import com.aliyun.polardbx.binlog.daemon.constant.CommandRet;
import com.aliyun.polardbx.binlog.daemon.pipeline.CommandPipeline;
import com.aliyun.polardbx.binlog.daemon.vo.CommandResult;
import com.aliyun.polardbx.binlog.daemon.vo.MachineInfo;

/**
 * Created by ziyang.lb
 */
public class MachineInfoCollector {
    private static final String CMD_DIR = "/tmp";
    String ip;

    public MachineInfoCollector(String ip) {
        this.ip = ip;
    }

    public MachineInfo getMachineInfo() throws Exception {
        CommandPipeline commandPipeline = new CommandPipeline(CMD_DIR);
        CommandResult commandResult = commandPipeline.execCommand(new String[] {"tsar -C"}, 1000);
        if (commandResult.getCode() == CommandRet.SUC) {
            MachineInfo machineInfo = new MachineInfo();
            machineInfo.from(commandResult.getMsg());
            return machineInfo;
        } else {
            return null;
        }
    }
}
